/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sasp_messages;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author mauriello
 */
public class NEWSupernodeCommand extends SASPCommand {
    String ipString;
    String aliasString;

    public String getAliasString() {
        return aliasString;
    }

    public void setAliasString(String aliasString) {
        this.aliasString = aliasString;
    }

    public String getIpString() {
        return ipString;
    }

    public void setIpString(String ipString) {
        this.ipString = ipString;
    }

    

    public NEWSupernodeCommand( ) {
        super( );
        this.setType(NEW_NODE);
    }

    @Override
    public void updateCommandBody( ) {
        try {
            JSONObject body = new JSONObject();
            body.put("Alias", aliasString);
            body.put("IPAddress", ipString);
            this.setCommandBody(body);
        } catch (JSONException ex) {
            Logger.getLogger(REQTableReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public NEWSupernodeCommand( int _o, int _d, int _m, String _ip, String _a ) {
        super( _o, _d, _m );
        this.setType(NEW_NODE);
        saspmanager.SASPManagerApp.addLine("NSC - New Super Node Command Generated");
        ipString = _ip;
        aliasString = _a;

        try {
            JSONObject body = new JSONObject();
            body.put("Alias", aliasString);
            body.put("IPAddress", ipString);
            this.setCommandBody(body);
        } catch (JSONException ex) {
            Logger.getLogger(REQTableReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public NEWSupernodeCommand( String _s ) {
        super( _s );

        try {
            saspmanager.SASPManagerApp.addLine("NSC - New Super Node Command Received");
            ipString = this.getCommandBody().getString("IPAddress");
            aliasString = this.getCommandBody().getString("Alias");
        } catch (JSONException ex) {
            Logger.getLogger(REQMasterReply.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    @Override
    public SASPReply execute() {
        saspmanager.SASPManagerApp.addLine("NSC - ACK Reply Generated");
        return null; //new ACKReply(this.getDestinationID(),this.getOriginatorID(),this.getMessageID());
    }

}
